package com.zbkj.dal.entity.fund;

import cn.hutool.core.util.IdUtil;
import com.zbkj.dal.base.constants.OrderConstants;
import com.zbkj.dal.base.enums.BooleanEnums;
import com.zbkj.dal.base.enums.FundAccountType;
import com.zbkj.dal.common.utils.CrmebUtil;
import lombok.Data;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;

import java.io.Serializable;
import java.math.BigDecimal;
import java.time.LocalDateTime;

/**
 * @author JinXinyu
 * @date 2024-02-08 17:17:04
 */
@Data
@TableName("eb_user_fund_account")
public class UserFundAccount implements Serializable {

    @TableId(value = "id", type = IdType.AUTO)
    private Integer id;

    /**
     * 账户类型：雅识
     */
    @TableField("fund_account")
    private String fundAccount;

    /**
     * 用户id
     */
    @TableField("user_id")
    private Integer userId;

    /**
     * 账户类型
     */
    @TableField("account_type")
    private String accountType;

    /**
     * 总余额
     */
    @TableField("total_amount")
    private BigDecimal totalAmount;

    /**
     * 可用余额
     */
    @TableField("available_amount")
    private BigDecimal availableAmount;

    /**
     * 在途余额
     */
    @TableField("frozen_amount")
    private BigDecimal frozenAmount;

    /**
     * 创建时间
     */
    @TableField("create_time")
    private LocalDateTime createTime;

    /**
     * 更新时间
     */
    @TableField("update_time")
    private LocalDateTime updateTime;

    /**
     * 是否删除
     */
    @TableField("is_deleted")
    private Integer deleted;

    public static UserFundAccount initAccount(Integer userId) {
        UserFundAccount userFundAccount = new UserFundAccount();
        userFundAccount.setFundAccount(CrmebUtil.getAccountNo(OrderConstants.CRAB_ROE_ACCOUNT_PREFIX, userId));
        userFundAccount.setUserId(userId);
        userFundAccount.setAccountType(FundAccountType.CRAB_ROE.name());
        userFundAccount.setTotalAmount(BigDecimal.ZERO);
        userFundAccount.setAvailableAmount(BigDecimal.ZERO);
        userFundAccount.setFrozenAmount(BigDecimal.ZERO);
        userFundAccount.setCreateTime(LocalDateTime.now());
        userFundAccount.setUpdateTime(LocalDateTime.now());
        userFundAccount.setDeleted(BooleanEnums.FALSE.getCode());
        return userFundAccount;
    }
}
